<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <div id="app">
        <router-link to="/login">登录</router-link>
        <router-view></router-view>
    </div>

    <template id="login">
        <div>
            用户名：<input type="text"><br>
            密码：<input type="password"><br>
            <button>登录</button>
        </div>
    </template>

    <template id="home">
        <div>
            <h3>这里是home</h3>
        </div>
    </template>

    <template id="goods">
        <div>
            <ul>
                <li>商品1</li>
                <li>商品2</li>
                <li>商品3</li>
                <li>商品4</li>
                <li>商品5</li>
                <li>商品6</li>
            </ul>
        </div>
    </template>

    <script src="../lib/Vue/vue.js"></script>
    <script src="../lib/Vue/vue-router.js"></script>
    <script>

        const router = new VueRouter({
            routes: [
                {
                    path: '/',
                    redirect: '/login'
                },
                {
                    path: '/login',
                    component: {
                        template: '#login'
                    }
                },
                {
                    path: '/home',
                    meta: {
                        title: 'home'
                    },
                    component: {
                        template: '#home'
                    },
                    beforeEnter: (to, from, next) => {
                        window.document.title = to.meta.title
                        next()
                    }
                },
                {
                    path: '/goods',
                    component: {
                        template: '#goods'
                    }
                }
            ]
        })

        var vm = new Vue({
            el: '#app',
            router
        })
    </script>
</body>
</html>